/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package its.mx.dsw2.view;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import mx.its.dsw2.Bl.scholarshipBlLocal;
import mx.itsc.ds2.model.Scholarship;

/**
 *
 * @author Martinez
 */
@ManagedBean
@SessionScoped
public class ScholarshipBean {
    //---------------EJB'S---------------------
    @EJB
    private scholarshipBlLocal scholarshipBl;
    //-----------------------------------------

    //----------------Variables-----------------
    Scholarship scholarship = new Scholarship();
    private List<Scholarship> scholarshipList = new ArrayList<Scholarship>();
    private String action;
    
    //------------------------------------------
    //----------------Actions-------------------
    public void prepareNew(ActionEvent evt) {
        action = "New";
        scholarship = new Scholarship();
    }

    public String processAction() {
        if (action.equalsIgnoreCase("New")) {
            scholarshipBl.agregate(scholarship);
        } else if (action.equalsIgnoreCase("Edit")) {
            scholarshipBl.modify(scholarship);
        } else if (action.equalsIgnoreCase("Delete")) {
            scholarshipBl.remove(scholarship);
        }
        action = "";
        return "Scholarshiplist";
    }

    public void prepareEdit(ActionEvent evt){
        action = "Edit";
        scholarshipList = scholarshipBl.findByScholarship(scholarship);
    }
    //------------------------------------------
    //-----------------Constructors-------------
    public ScholarshipBean() {
    }
    //------------------------------------------

    //------------------Getter and Setter-------
    public Scholarship getScholarship() {
        return scholarship;
    }

    public void setScholarship(Scholarship scholarship) {
        this.scholarship = scholarship;
    }

    public List<Scholarship> getScholarshipList() {
        scholarshipList = scholarshipBl.findAll();
        return scholarshipList;
    }

    public void setScholarshipList(List<Scholarship> scholarshipList) {
        this.scholarshipList = scholarshipList;
    }
    //------------------------------------------
}
